import { RoleId } from "@/types/role.d";

export type DefaultRoutes = {
  menuUrl: string;
  menuName: string;
  routeName: string;
  icon: string;
  parentPath: string;
  role: RoleId[];
  children?: DefaultRoutes[];
}

/**
 * 这里的 defaultRoutes 是为了在一开始对接项目的时候，后端人员还没有准备好菜单接口，导致前端开发者不能进入主页面。
 * 所以这里返回默认的菜单数据，同时也向大家说明菜单数据的数据结构。后端的菜单接口一定要按这个格式去返回json数据，否则会解析菜单失败
 */
export const defaultRoutes: DefaultRoutes[] = [
  {
    menuUrl: '/index',
    menuName: '仪表盘',
    routeName: 'dashborad',
    icon: 'icon-dashboard',
    parentPath: '',
    role: [
      RoleId.Admin,
      RoleId.Finance,
      RoleId.Manager
    ],
    children: [
      {
        parentPath: '/index',
        menuUrl: '/index/custom',
        menuName: '客户管理',
        routeName: 'custom',
        role: [
          RoleId.Admin,
          RoleId.Finance,
          RoleId.Manager
        ],
      },
      {
        parentPath: '/index',
        menuUrl: '/index/flow',
        menuName: '流水',
        routeName: 'flow',
        role: [
          RoleId.Admin,
          RoleId.Finance,
        ],
      },
      {
        parentPath: '/index',
        menuUrl: '/index/workPlace',
        menuName: '工作台',
        routeName: 'workPlace',
        role: [
          RoleId.Admin,
          RoleId.Finance,
          RoleId.Manager
        ]
      },
    ],
  },
  {
    menuUrl: '/system',
    menuName: '系统管理',
    icon: 'icon-settings',
    parentPath: '',
    routeName: 'system',
    role: [
      RoleId.Admin,
    ],
    children: [
      {
        parentPath: '/system',
        menuUrl: '/system/user',
        menuName: '用户管理',
        routeName: 'user',
        isRootPath: true,
        role: [
          RoleId.Admin,
        ],
      },
      // {
      //   parentPath: '/system',
      //   menuUrl: '/system/role',
      //   menuName: '角色管理',
      // },
      // {
      //   parentPath: '/system',
      //   menuUrl: '/system/menu',
      //   menuName: '菜单管理',
      // },
    ],
  },
]


function filterRole(route: DefaultRoutes) {

}

export const filterRoutes = (roleId: RoleId) => {
  return defaultRoutes.filter(route => route.role.includes(roleId))
}
